<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script>
    /* 
        字符串相关
        1. 字符串的常见方法
            charAt(index)  charCodeAt(index)   String.fromCharCode()
            indexOf()   lastIndexOf()   includes()
            concat()    slice/substring/substr   split()
            toUpperCase()/toLowerCase()
            trim()
            search()  match()  replace()

            repeat   padStart()和padEnd()

            String.prototype.repeat = function(n){
                var str = ""
                for(var i = 1; i <= n; i++){
                    str += this;
                }
                return str;
            }

        2. 字符统计 => 统计字符出现的次数
            var str = "abcbbbacdbc";


        3. 字符串解析  => 将参数数据队列解析为对象
            "name=张三&pwd=12312&phone=173xxxx1517&&email=12313@qq.com"
            {name:"xxx",pwd="xxx",phone:"xxx",email:"xxx"}
    
    */


    // 2. 字符统计 => 统计字符出现的次数
    // a. 先去重 在统计
    
    var str = "abcbbbacdbc";

    // var newStr = "";
    // for(var char of str){
    //     if(newStr.indexOf(char) == -1){
    //         newStr += char;
    //     }
    // }
    // console.log(newStr);

    // var s = new Set(str);
    // console.log(s);
    // var arr = [...s];
    // var arr = Array.from(s);
    // console.log(arr);  


    /* var obj = {};
    for(var char of str){
        if(Object.hasOwn(obj,char)){
            obj[char]++;
        }else{
            obj[char] = 1;
        }
    }
    console.log(obj);

    console.log(Object.keys(obj)); */

    var str = "name=张三&pwd=12312&phone=173xxxx1517&email=12313@qq.com"

    /* var list = str.split("&");
    console.log(list);

    var obj = {}
    list.forEach(v=>{
        var key = v.split("=")[0];
        var val = v.split("=")[1];
        obj[key] = val
    })
    console.log(obj); */


    /* var  sp =  new URLSearchParams(str);
    console.log(sp);
    
    // console.log(sp.toString());

    console.log(sp.get("name"));
    console.log(sp.get("pwd"));

    var obj = {}
    sp.forEach((val,key)=>{
        console.log(key,val);
        obj[key] = val
    })
   console.log(obj); */

   var sp =  new URLSearchParams(str);
   console.log(sp);

   var obj = Object.fromEntries(Array.from(sp));
   console.log(obj);





</script>
</html>